package com.wry.im.handler;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * <h1> 关闭服务器的处理器 <h1>
 *
 * @author wry
 * @since 2023/4/27 14:51
 */
@Component
@ChannelHandler.Sharable
@Slf4j
public class CloseServerHandler extends SimpleChannelInboundHandler<CloseWebSocketFrame> {

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, CloseWebSocketFrame closeWebSocketFrame) throws Exception {
       // 客户端连接关闭时的处理
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.fireExceptionCaught(cause);
    }
}
